package com.space.user.controller;

import com.alibaba.fastjson.JSON;
import com.space.client.dto.ModifyUserInfoCommand;
import com.space.components.response.Response;
import com.space.components.response.SingleResponse;
import com.space.client.api.UserInfoServiceI;
import com.space.client.dto.UserInfoDTO;
import com.space.components.exception.catcher.ExceptionCatcher;
import com.space.components.token.TokenParam;
import com.space.components.token.TokenParser;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.*;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/4/13 4:34 下午
 */
@RestController
@ExceptionCatcher
@TokenParser
public class InfoController {
    @Autowired
    private ConfigurableApplicationContext applicationContext;

    @Autowired
    private UserInfoServiceI userInfoServiceI;

    @GetMapping(value = "/user/create")
    public Response info() {
        userInfoServiceI.createUserInfo();
        return Response.buildSuccess();
    }

    @GetMapping(value = "/user/getInfo")
    public SingleResponse<UserInfoDTO> getInfo(A a, @TokenParam Integer userId) {
        System.out.println("-------------");
        System.out.println(a.getId());
        return SingleResponse.of(userInfoServiceI.getUserInfo(userId));
    }

    @Data
    public static class A {
        private Integer id;
    }

    @GetMapping(value = "/user/modifyInfo")
    public Response modifyUserInfo(@TokenParam Integer userId) {
        userInfoServiceI.modifyUserInfo(
                ModifyUserInfoCommand.builder()
                        .userId(userId)
                        .nickname("Fei")
                        .build()
        );
        return Response.buildSuccess();
    }
}
